package com.sgb.kjwl.viewmodel.enterprise;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.EnterpriseAPIManager;
import com.sgb.kjwl.model.entity.ParentAreaEntity;
import com.swgk.core.base.model.entity.BaseEntity;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SearchServiceModel extends AndroidViewModel {
    public MutableLiveData<Integer> ShowLoading = new MutableLiveData<>();
    public MutableLiveData<List<ParentAreaEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>>> typeList = new MutableLiveData<>();
    public String mitemid;


    public SearchServiceModel(@NonNull @NotNull Application application) {
        super(application);
    }

    /**
     * 获取服务类别
     */
    public void getServiceType() {
        ShowLoading.postValue(1);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getServiceCategoryOption().enqueue(new Callback<BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>>>> call, Response<BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>>>> response) {
                ShowLoading.postValue(2);
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    typeList.postValue(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<ParentAreaEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>>>> call, Throwable t) {
                ShowLoading.postValue(2);
            }
        });
    }
}


